﻿<MudDropContainer @ref="_container" T="SimpleDropItem"
				  Items="_items" ItemsSelector="@((item,dropzone) => item.ZoneIdentifier == dropzone)"
				  Class="d-flex"
				  DraggingClass="my-special-dragging-class" ItemDraggingClass="my-special-item-dragging-class"
				  ItemDropped="ItemUpdated">
	<ChildContent>
		<MudDropZone T="SimpleDropItem" Identifier="Column 1" Class="first-drop-zone" />
		<MudDropZone T="SimpleDropItem" Identifier="Column 2" Class="second-drop-zone" />
	</ChildContent>
	<ItemRenderer>
		<MudText>@context.Name</MudText>
	</ItemRenderer>
</MudDropContainer>

@code {
    private MudDropContainer<SimpleDropItem> _container = null!;
    private readonly List<SimpleDropItem> _items =
    [
        new("1", "Column 1"),
        new("2", "Column 2"),
        new("3", "Column 1")
    ];

	private static void ItemUpdated(MudItemDropInfo<SimpleDropItem> dropItem)
    {
        if (dropItem.Item is null)
        {
            return;
        }

        dropItem.Item.ZoneIdentifier = dropItem.DropzoneIdentifier;
    }

	public void AddItem() => _items.Add(new SimpleDropItem($"{_items.Count + 1}","Column 2"));

	public void RemoveLastItem() => _items.RemoveAt(_items.Count - 1);

	public async Task InvokeRefresh() => await InvokeAsync(_container.Refresh);

    public class SimpleDropItem(string name, string zoneIdentifier)
    {
        public string Name { get; set; } = name;

        public string ZoneIdentifier { get; set; } = zoneIdentifier;
    }
}
